package de.crm.storage.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import de.crm.storage.Customer;
import de.crm.storage.enums.Sex;
import de.crm.storage.enums.Status;

public class CustomerImpl implements Customer {

	private Integer id;
	private Sex sex;

	private String firstname;
	private String lastname;

	private Date birthdate;

	private Integer volume;
	private Integer expectedsales;


	private Status status;

	private java.util.List<String> fieldList = null;


	public void setId(Integer id) {
		this.id = id;
	}


	public Integer getId() {
		return id;
	}


	public void setSex(Sex sex) {
		this.sex = sex;
	}


	public Sex getSex() {
		return sex;
	}


	public void setName(String name) {
		this.firstname = name;
	}


	public String getName() {
		return firstname;
	}


	public void setLastname(String lastname) {
		this.lastname = lastname;
	}


	public String getSurname() {
		return lastname;
	}


	public void setBirthdate(Date birthdate) {
		this.birthdate = birthdate;
	}


	public Date getBirthdate() {
		return birthdate;
	}


	public void setVolume(Integer volume) {
		this.volume = volume;
	}


	public Integer getVolume() {
		return volume;
	}


	public void setExpectedsales(Integer expectedsales) {
		this.expectedsales = expectedsales;
	}


	public Integer getExpectedsales() {
		return expectedsales;
	}


	public void setStatus(Status status) {
		this.status = status;
	}


	public Status getStatus() {
		return status;
	}


	public Iterator<String> fieldIterator() {
		this.fieldList = new ArrayList<String>();

		this.fieldList.add(String.valueOf(this.getId()));
		this.fieldList.add(this.getName());
		this.fieldList.add(this.getSurname());
		this.fieldList.add(String.valueOf(this.getExpectedsales()));
		this.fieldList.add(String.valueOf(this.getVolume()));
		this.fieldList.add(String.valueOf(this.getBirthdate()));
		this.fieldList.add(String.valueOf(this.getSex()));
		this.fieldList.add(String.valueOf(this.getStatus()));

		return this.fieldList.iterator();
	}


	public void setFields(List<String> fieldList) {
		if( !fieldList.get(0).equals("") ) {
			this.setId(Integer.parseInt(fieldList.get(0)));
		}

		this.setName(fieldList.get(1));
		this.setLastname(fieldList.get(2));
		if(  !fieldList.get(3).equals("") ) {
			this.setExpectedsales(Integer.parseInt(fieldList.get(3)));
		}
		if(  !fieldList.get(4).equals("") ) {
			this.setVolume(Integer.parseInt(fieldList.get(4)));
		}
		if(  !fieldList.get(5).equals("") ) {
			this.setBirthdate(new Date(fieldList.get(5)));
		}
		if(  !fieldList.get(6).equals("") ) {
			this.setSex(Sex.valueOf(fieldList.get(6)));
		}
		if(  !fieldList.get(7).equals("") ) {
			this.setStatus(Status.valueOf(fieldList.get(7)));
		}
	}

}
